package com.ucode.model.hrm.form;

import cn.hutool.core.util.ObjUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.*;
import java.math.BigDecimal;
import java.time.LocalDate;

@Schema(description = "人力资源管理系统 - 员工离职Form")
@Data
@EqualsAndHashCode
@ToString(callSuper = true)
public class HrmEmployResignationForm {

    /**
     * 员工ID
     */
    @Schema(description = "员工ID", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "员工ID不能为空")
    private Long employeeId;

    /**
     * 离职日期
     */
    @Schema(description = "离职日期", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "离职日期不能为空")
    private LocalDate resignationDate;
    /**
     * 离职原因
     */
    @Schema(description = "离职原因", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "离职原因不能为空")
    @Size(max = 500, message = "离职原因不能超过 255 个字符")
    private String resignReason;
    /**
     * 离职类型:1-个人原因，2-协商一致，3-甲方原因
     */
    @Schema(description = "离职类型", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "离职类型不能为空")
    @Range(min = 1, max = 3, message = "离职类型范围在1-3之间")
    private Integer resigType;

    @Schema(description = "社保缴纳截止时间", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "社保缴纳截止时间不能为空")
    private LocalDate sspEndTime;
    /**
     * 是否有经济补偿金
     */
    @Schema(description = "是否有经济补偿金", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "是否有经济补偿金不能为空")
    private Boolean economic = false;
    /**
     * 经济补偿金
     */
    @Schema(description = "经济补偿金", requiredMode = Schema.RequiredMode.AUTO)
    @Min(value = 0, message = "经济补偿金最小值为0")
    private BigDecimal compensation;
    /**
     * 补偿费用总金额
     */
    @Schema(description = "补偿费用总金额", requiredMode = Schema.RequiredMode.AUTO)
    @Min(value = 0, message = "补偿费用总金额最小值为0")
    private BigDecimal comFeeTotal;
    /**
     * 补偿金发放时间
     */
    @Schema(description = "补偿金发放时间", requiredMode = Schema.RequiredMode.AUTO)
    private LocalDate comProvideTime;

    @AssertTrue(message = "经济补偿金不能为空")
    public boolean isCompensationCheck() {
        if(this.economic && ObjUtil.isNull(this.compensation)){
            return false;
        }
        return true;
    }

    @AssertTrue(message = "补偿费用总金额不能为空")
    public boolean isComFeeTotalCheck() {
        if(this.economic && ObjUtil.isNull(this.comFeeTotal)){
            return false;
        }
        return true;
    }

    @AssertTrue(message = "补偿金发放时间不能为空")
    public boolean isComProvideTimeCheck() {
        if(this.economic && ObjUtil.isNull(this.comProvideTime)){
            return false;
        }
        return true;
    }


}
